package com.eascs.ticket.ticket.vo;

import java.util.HashMap;
import java.util.Map;

import com.eascs.common.util.StringUtil;

public class OrderByHelper {
	static final Map<String, String> ORDER_BY_EXPRESSION_MAP = new HashMap<>();
	static {
		ORDER_BY_EXPRESSION_MAP.put(OrderByConstant.ORDER_BY_DUEDATE, "t.due_date asc,v.publish_prod_time asc, t.publish_prod_time asc,t.project_id asc,v.id asc,v.title asc,ts.order_code asc");
		ORDER_BY_EXPRESSION_MAP.put(OrderByConstant.ORDER_BY_OPERATOR, "t.operator_name asc,t.due_date,v.id asc,v.title asc,t.project_id asc,ts.order_code asc");
		ORDER_BY_EXPRESSION_MAP.put(OrderByConstant.ORDER_BY_VERSION, "v.publish_prod_time asc, t.publish_prod_time asc,t.project_id asc,v.id asc,t.due_date asc,v.title asc,ts.order_code asc");
		ORDER_BY_EXPRESSION_MAP.put(OrderByConstant.ORDER_BY_STATUS, "ts.order_code asc,v.due_date asc,v.title asc,t.project_id asc");
		ORDER_BY_EXPRESSION_MAP.put(OrderByConstant.ORDER_BY_CREATE_DATE, "t.create_date desc,t.due_date asc");
	}

	public static String getOrderExpression(String orderBy, String defaultOrderExpression) {
		String order = ORDER_BY_EXPRESSION_MAP.get(orderBy);
		if (StringUtil.hasText(order))
			return order;
		return defaultOrderExpression;
	}

	public static String getOrderExpression(String orderBy) {
		return OrderByHelper.getOrderExpression(orderBy, null);
	}

}
